/**
 * 创建数据模型（mongoose 操作数据是基于数据模型）
 * 数据校验
 */
 const mongoose = require("mongoose");

 const pwdReg = /^[A-Za-z0-9]+$/;
 const emailReg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
 
 const userSchema = mongoose.Schema({
   username: {
     type: String,
    //  require: [true, '请填写用户名'],
    //  validate: [
    //    {validator: (value) => value.length > 5 && value.length < 13, msg: "用户名5-13位"},
    //  ]
   },
   password: {
     type: String,
    //  require: [true, '请填写密码'],
    //  validate: [
    //    {validator: (value) => value.length > 8, msg: "密码须大于8位"},
    //    {validator: (value) => pwdReg.test(value), msg: "密码格式不正确"},
    //  ]
   },
   email: {
     type: String,
     require: true,
    //  validate: [
    //    {validator: (value) => emailReg.test(value), msg: "邮箱格式不正确"},
    //  ]
   },
   nickname: {
     type: String,
   },
   createdAt: {
     type: Date,
     default: Date.now,
   },
 });
 
 module.exports = mongoose.model("user", userSchema);
 